home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / amisl090.zip / AMISHOTK.ASM < prev    next >
Assembly Source File  |  1992-09-12  |  5KB  |  213 lines

  1. ;-----------------------------------------------------------------------
  2. ; Alternate Multiplex Interrupt Specification Library
  3. ; AMISHOTK.ASM    Public Domain 1992 Ralf Brown
  4. ;        You may do with this software whatever you want, but
  5. ;        common courtesy dictates that you not remove my name
  6. ;        from it.
  7. ;
  8. ; Version 0.90
  9. ; LastEdit: 9/12/92
  10. ;-----------------------------------------------------------------------
  11.  
  12.     INCLUDE AMIS.MAC
  13.  
  14. _TEXT SEGMENT PUBLIC BYTE 'CODE'
  15.     ASSUME    CS:_TEXT
  16.  
  17. ;-----------------------------------------------------------------------
  18. ; entry: AX,CX = required shift states for two TSRs
  19. ; exit:     AX,CX adjusted
  20. ;
  21. fix_multishifts proc near
  22.     xchg    cx,ax
  23.     call    fix_multishifts_0
  24.     xchg    cx,ax
  25.     ;; fall through
  26. fix_multishifts_0:
  27.     test    ax,HK_ANYSHIFT
  28.     jz    fms_1
  29.     test    cx,HK_LSHIFT or HK_RSHIFT
  30.     jz    fms_1
  31.     and    ax,not HK_ANYSHIFT
  32. fms_1:
  33.     test    ax,HK_ANYCTRL
  34.     jz    fms_2
  35.     test    cx,HK_LCTRL or HK_RCTRL
  36.     jz    fms_2
  37.     and    ax,not HK_ANYCTRL
  38. fms_2:
  39.     test    ax,HK_ANYALT
  40.     jz    fms_3
  41.     test    cx,HK_LALT or HK_RALT
  42.     jz    fms_3
  43.     and    ax,not HK_ANYALT
  44. fms_3:
  45.     ret
  46. fix_multishifts endp
  47.  
  48. ;-----------------------------------------------------------------------
  49. ; entry: DS:SI -> hotkey list of already-installed TSR
  50. ;     ES:DI -> hotkey list of current TSR
  51. ; exit:     AX = conflict flags (see below)
  52. ;
  53. check_hotkey_conflict proc near
  54.     push    bp
  55.     push    si
  56.     xor    bp,bp            ; no conflicts yet
  57.     cld                ; string operations move up in memory
  58.     inc    si
  59.     mov    cl,[si]            ; number of hotkeys to check
  60.     or    cl,cl            ; any hotkeys?
  61.     jz    chc_done
  62.     inc    si            ; skip list header
  63. chc_loop:
  64.     push    di
  65.     inc    di
  66.     mov    ch,es:[di]        ; number of hotkeys in list
  67.                     ; we already know this number is nonzero
  68.     inc    di            ; skip list header
  69. chc_inner_loop:
  70.     push    cx
  71.     cmpsb                ; check if scan codes the same
  72.     jne    chc_inner_next        ; skip if scan codes different
  73.     mov    ax,[si]
  74.     mov    bx,[si+2]
  75.     mov    cx,es:[di]        ; get required shift states
  76.     mov    dx,es:[di+2]        ; get disallowed shift states
  77.     ;
  78.     ; first, check for an exact match
  79.     ;
  80.     cmp    cx,ax
  81.     jne    chc_maybe_superset
  82.     cmp    dx,bx
  83.     jne    chc_maybe_superset
  84.     mov    ax,HC_EXACT
  85.     jmp short chc_set_conflict_flag
  86. chc_maybe_superset:
  87.     ; superset if we require more shift states than the other one does
  88.     ; or if the other one has more disallowed shift states
  89.     ;
  90.     ; need special cases for either-shift vs one-shift, same for Ctrl,Alt
  91.     ;
  92.     call    fix_multishifts
  93.     ;
  94.     ; after the preceding adjustments, check the bits
  95.     ;
  96.     push    ax            ; preserve AX
  97.     not    ax
  98.     test    ax,cx            ; states not present in other?
  99.     pop    ax            ; restore AX
  100.     jz    chc_maybe_superset_2
  101.     push    dx            ; preserve DX
  102.     not    dx
  103.     test    dx,bx            ; states not present in ours?
  104.     pop    dx            ; restore DX
  105.     jz    chc_maybe_subset
  106.     ;
  107.     ; now make sure it is a superset by doing the test the other way around
  108.     ;
  109. chc_maybe_superset_2:
  110.     not    cx
  111.     test    cx,ax            ; states not present in ours?
  112.     jnz    chc_inner_next        ; if yes, not a superset
  113.     not    bx
  114.     test    bx,dx            ; states not present in other?
  115.     jnz    chc_inner_next        ; if yes, not a superset
  116.     mov    ax,HC_SUPERSET
  117.     jmp short chc_set_conflict_flag
  118. chc_maybe_subset:
  119.     ; subset if we require fewer shift states than the other one does
  120.     ; or if we have more disallowed shift states
  121.     ;
  122.     not    cx
  123.     test    cx,ax            ; states not present in ours?
  124.     jz    chc_is_subset
  125.     not    bx
  126.     test    bx,dx            ; states not present in other?
  127.     jz    chc_inner_next
  128. chc_is_subset:
  129.     mov    ax,HC_SUBSET
  130. chc_set_conflict_flag:
  131.     test    byte ptr [si+4],HK_MONITOR
  132.     jz    chc_set_flag
  133.     test    byte ptr es:[di+4],HK_CHAINBEFORE or HK_CHAINAFTER
  134.     jz    chc_set_flag
  135.     mov    ax,HC_MONITOR        ; no actual conflict, but let caller know
  136. chc_set_flag:
  137.     or    bp,ax
  138. chc_inner_next:
  139.     pop    cx
  140.     add    di,5            ; move to next hotkey record
  141.     dec    ch
  142.     jnz    chc_inner_loop
  143.     pop    di
  144.     add    si,5            ; move to next hotkey record
  145.     dec    cl
  146.     jnz    chc_loop
  147. chc_done:
  148.     mov    ax,bp            ; AX <- conflict flags
  149.     pop    si
  150.     pop    bp
  151.     ret
  152. check_hotkey_conflict endp
  153.  
  154. ;-----------------------------------------------------------------------
  155. ; entry: DX:AX -> hotkey list
  156. ; exit:  ZF set if no hotkey conflicts
  157. ;     ZF clear if hotkey conflict
  158. ;     AX = type of conflicts
  159. ;        bit 0: one or more exact keys already in use
  160. ;        bit 1: one or more superset keys already in use
  161. ;        bit 2: one or more subset keys already in use
  162. ;        bit 7: some other TSR is monitors one of our passed-thru keys
  163. ;
  164. public check_if_hotkeys_used
  165. check_if_hotkeys_used proc DIST
  166.     push    bp
  167.     xor    bp,bp            ; conflict flags; no conflicts yet
  168.     push    es
  169.     push    di
  170.     mov    es,dx
  171.     mov    di,ax
  172.     cmp    byte ptr es:[di+1],0    ; does this TSR have any hotkeys?
  173.     je    cihu_done        ; if not, no conflicts
  174.     push    ds
  175.     push    si
  176.     mov    ah,0
  177. check_hotkeys_loop:
  178.     push    ax            ; save multiplex number
  179.     mov    al,0
  180.     push    di
  181.     int    2Dh
  182.     pop    di
  183.     cmp    al,AMIS_SUCCESSFUL
  184.     jne    cihu_next
  185.     pop    ax
  186.     push    ax
  187.     mov    al,5            ; function "get hotkeys"
  188.     int    2Dh
  189.     cmp    al,AMIS_SUCCESSFUL
  190.     jne    cihu_next
  191.     mov    ds,dx
  192.     mov    si,bx
  193.     call    check_hotkey_conflict
  194.     or    bp,ax            ; add any conflicts to conflict flags
  195. cihu_next:
  196.     pop    ax            ; get back multiplex number
  197.     inc    ah
  198.     jne    check_hotkeys_loop
  199. cihu_done:
  200.     pop    si
  201.     pop    ds
  202.     pop    di
  203.     pop    es
  204.     mov    ax,bp            ; AX <- conflict flags
  205.     pop    bp
  206.     test    ax,HC_IS_CONFLICT    ; set ZF if no conflicts
  207.     ret
  208. check_if_hotkeys_used endp
  209.  
  210.  
  211. _TEXT ENDS
  212.     END
  213.